﻿#include "InstructionTurnTableRateMode.h"

__SCRIPTINSTRUCTION_REGISTER(InstructionTurnTableRateMode,ScriptInstruction::Instruction_TurnTable_RateMode,&InstructionTurnTableRateMode::fromByteArray1);

InstructionTurnTableRateMode::InstructionTurnTableRateMode()
{
  instructionFlag = Instruction_TurnTable_RateMode;
}

InstructionTurnTableRateMode::InstructionTurnTableRateMode(InstructionTurnTableRateMode const& instructionTurnTableRateMode)
{
  *this=instructionTurnTableRateMode;
}

InstructionTurnTableRateMode& InstructionTurnTableRateMode::operator=(InstructionTurnTableRateMode const & instructionTurnTableRateMode)
{
  *(ScriptInstruction*)this=instructionTurnTableRateMode;
  rate=instructionTurnTableRateMode.rate;
  acceleration=instructionTurnTableRateMode.acceleration;
  return *this;
}

InstructionTurnTableRateMode::~InstructionTurnTableRateMode()
{}

QString InstructionTurnTableRateMode::toString()
{
  return QStringLiteral("设置速率模式，速率：%1°/s，加速度：%2°/s²")
      .arg(rate,0,'f',4)
      .arg(acceleration,0,'f',4);
}

QByteArray InstructionTurnTableRateMode::toByteArray()
{
  return QByteArray().append((char*)&rate,sizeof (rate))
      .append((char*)&acceleration,sizeof (acceleration));
}

InstructionTurnTableRateMode* InstructionTurnTableRateMode::clone()
{
  return new InstructionTurnTableRateMode(*this);
}

ScriptInstruction* InstructionTurnTableRateMode::fromByteArray1(char * const src,int size,int * offset)
{
  if((size-*offset)<byteArraySize)
    {
      return Q_NULLPTR;
    }
  InstructionTurnTableRateMode* instructionTurnTableRateMode=new InstructionTurnTableRateMode();
  instructionTurnTableRateMode->setRate(*(float*)(src+*offset));
  offset+=sizeof (rate);
  instructionTurnTableRateMode->setAcceleration(*(float*)(src+*offset));
  offset+=sizeof (acceleration);
  return instructionTurnTableRateMode;
}

float InstructionTurnTableRateMode::getRate()
{
  return rate;
}

InstructionTurnTableRateMode* InstructionTurnTableRateMode::setRate(float rate)
{
  this->rate=rate;
  return this;
}

float InstructionTurnTableRateMode::getAcceleration()
{
  return acceleration;
}

InstructionTurnTableRateMode* InstructionTurnTableRateMode::setAcceleration(float acceleration)
{
  this->acceleration=acceleration;
  return this;
}
